// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2025 Cloud_Yun (1770669041@qq.com). All Rights Reserved.
 */
#ifndef _ZRAM_ATGC_H
#define _ZRAM_ATGC_H

#include <linux/rbtree.h>
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/workqueue.h>

#define ATGC_ENTRY_EXPIRE_MS 30000 /* 30秒不活跃视为过期 */
#define HIGH_PRIO_THRESHOLD  0     /* oom_score_adj<=0为高优先级 */

struct zram_atgc_entry {
    struct rb_node rb_node;
    pid_t pid;
    int oom_score_adj;
    unsigned long last_used;
    struct list_head list;
};

struct zram_atgc {
    struct rb_root root;
    spinlock_t lock;
    struct delayed_work gc_work;
    atomic_t enabled;
    unsigned long expire_jiffies;
    int threshold;
};

void zram_atgc_init(struct zram_atgc *atgc);
void zram_atgc_destroy(struct zram_atgc *atgc);
bool zram_atgc_should_compress(struct zram_atgc *atgc, struct task_struct *task);
void zram_atgc_update(struct zram_atgc *atgc, struct task_struct *task);

#endif /* _ZRAM_ATGC_H */
